package p02_queue;

import java.util.Scanner;

public class P2 {
    public static void main(String[] args) {
        // 创建一个队列
        CircleArrayQueue queue = new CircleArrayQueue(2);
        char key = ' '; // 用于接收用户数据
        Scanner scanner = new Scanner(System.in);
        boolean loop = true;

        //输出一个菜单
        System.out.println("s(show): 显示队列");
        System.out.println("e(exit): 退出程序");
        System.out.println("a(add): 添加数据到队列");
        System.out.println("g(get): 从队列取出数据");
        System.out.println("p(peek): 查看队列头的数据");

        // 程序启动
        System.out.print("程序启动，请输入指令：");
        while (loop) {
            key = scanner.next().charAt(0); // 接收第一个字符
            switch (key) {
                case 's':
                    System.out.println("队列为：");
                    queue.show();
                    break;
                case 'e':
                    scanner.close();
                    loop = false;
                    break;
                case 'a':
                    System.out.print("请输入一个字：");
                    int a = scanner.nextInt();
                    queue.add(a);
                    break;
                case 'g':
                    int g = queue.get();
                    System.out.printf("取出的数据是：%d", g);
                    System.out.println();
                    break;
                case 'p':
                    int p = queue.peek();
                    System.out.printf("队列头的数据是：%d", p);
                    System.out.println();
                    break;
                case 'z':
                    int z = queue.size();
                    System.out.printf("队列头的size是：%d", z);
                    System.out.println();
                    break;
                default:
                    break;
            }
        }
        System.out.println("程序退出！");
    }
}
